Skip to content

Fix usagetype parameter autocomplete #156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 13, 2025

Conversation

hsato03
Copy link
Contributor

@hsato03 hsato03 commented Jan 1, 2025

Currently, when using autocomplete in the usagetype parameter (present in APIs such as quotaPresetVariableList and quotaCreateTariff) the CLI panics.

$ cmk  
Apache CloudStack 🐵 CloudMonkey 6.4.0
Report issues: https://github.com/apache/cloudstack-cloudmonkey/issues

panic: interface conversion: interface {} is float64, not string

goroutine 36 [running]:
github.com/apache/cloudstack-cloudmonkey/cli.buildArgOptions(0xc000f48000?, 0x0)
	/Users/rohit/lab/apache/cloudstack-cloudmonkey/cli/completer.go:126 +0x8c5
github.com/apache/cloudstack-cloudmonkey/cli.(*autoCompleter).Do(0xc00004f790, {0xc000e9e3f0, 0x0?, 0x24}, 0x24)
	/Users/rohit/lab/apache/cloudstack-cloudmonkey/cli/completer.go:402 +0x136c
github.com/chzyer/readline.(*opCompleter).OnComplete(0xc000130ee0)
	/Users/rohit/lab/apache/cloudstack-cloudmonkey/vendor/github.com/chzyer/readline/complete.go:101 +0x10d
github.com/chzyer/readline.(*Operation).ioloop(0xc000130e00)
	/Users/rohit/lab/apache/cloudstack-cloudmonkey/vendor/github.com/chzyer/readline/operation.go:180 +0xc8a
created by github.com/chzyer/readline.NewOperation in goroutine 1
	/Users/rohit/lab/apache/cloudstack-cloudmonkey/vendor/github.com/chzyer/readline/operation.go:88 +0x2d6

This PR aims to fix this bug and allow users to use the completer for the usagetype parameter.

Screenshot from 2025-01-01 15-30-09

@shwstppr
Copy link
Contributor

@hsato03 can you please check the review comment?

@shwstppr shwstppr added this to the 6.5.0 milestone Jul 24, 2025
@shwstppr shwstppr closed this Aug 7, 2025
@shwstppr shwstppr reopened this Aug 7, 2025
Copy link
Contributor

@shwstppr shwstppr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code lgtm

@shwstppr shwstppr requested a review from winterhazel August 7, 2025 12:38
@shwstppr shwstppr closed this Aug 8, 2025
@shwstppr shwstppr reopened this Aug 8, 2025
Copy link

github-actions bot commented Aug 8, 2025

✅ Build complete for PR #156.

🔗 Download the cmk binaries (expires on August 18, 2025)

@DaanHoogland
Copy link
Contributor

a remark and a question @hsato03 :

  1. I tried with the list usagerecords, but it turns out the parameter is “type” and not "usagetype” that might be worth fixing as well.
  2. I have other usage and quota enabled but do not get any quota commands except for quota isenabled. What else might I be forgetting?

@DaanHoogland
Copy link
Contributor

@hsato03 (cc @winterhazel ) can you update on this? It would be nice to include it in an upcoming release.

@winterhazel
Copy link
Member

I have other usage and quota enabled but do not get any quota commands except for quota isenabled. What else might I be forgetting?

@DaanHoogland did you restart your Management Server(s) after setting quota.enable.service to true in order to enable the plugin? Also, are the Quota APIs allowed in your role?

I tried with the list usagerecords, but it turns out the parameter is “type” and not "usagetype” that might be worth fixing as well.

+1

Copy link
Member

@winterhazel winterhazel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I tested the autocomplete for usagetype in the Quota APIs. It is working as intended.

./bin/cmk
Apache CloudStack 🐵 CloudMonkey 6.4.0
Report issues: https://github.com/apache/cloudstack-cloudmonkey/issues

(admin) 🐱 > quota presetvariableslist usagetype=
1 (RUNNING_VM)                2 (ALLOCATED_VM)              3 (IP_ADDRESS)                4 (NETWORK_BYTES_SENT)        5 (NETWORK_BYTES_RECEIVED)    6 (VOLUME)                    
7 (TEMPLATE)                  8 (ISO)                       9 (SNAPSHOT)                  10 (SECURITY_GROUP)           11 (LOAD_BALANCER_POLICY)     12 (PORT_FORWARDING_RULE)     
13 (NETWORK_OFFERING)         14 (VPN_USERS)                21 (VM_DISK_IO_READ)          22 (VM_DISK_IO_WRITE)         23 (VM_DISK_BYTES_READ)       24 (VM_DISK_BYTES_WRITE)      
25 (VM_SNAPSHOT)              26 (VOLUME_SECONDARY)         27 (VM_SNAPSHOT_ON_PRIMARY)   28 (BACKUP)                   29 (BUCKET)                   30 (NETWORK)                  
31 (VPC)        

@hsato03 @DaanHoogland regarding the completion for type in listUsageRecords, I think that we can address it separately, as this issue is not exclusive to usage type completion. Other APIs that have the type parameter are not completed either, even though some of them have APIs that return the possible values. listAlerts is an example.

@DaanHoogland
Copy link
Contributor

right ,

@hsato03 @DaanHoogland regarding the completion for type in listUsageRecords, I think that we can address it separately, as this issue is not exclusive to usage type completion. Other APIs that have the type parameter are not completed either, even though some of them have APIs that return the possible values. listAlerts is an example.

I did not mean to say in this PR but yes other type parameters (or other enum values) suffer the same.

I have other usage and quota enabled but do not get any quota commands except for quota isenabled. What else might I be forgetting?

@DaanHoogland did you restart your Management Server(s) after setting quota.enable.service to true in order to enable the plugin? Also, are the Quota APIs allowed in your role?

I had restarted after enabling the usage service but not the. quota service :doh:. Tested it with quota tariffcreate usagetype=

cc @shwstppr

@shwstppr shwstppr merged commit 902d732 into apache:main Aug 13, 2025
6 checks passed
shwstppr pushed a commit to shwstppr/cloudstack-cloudmonkey that referenced this pull request Aug 13, 2025
* Fix usage type autocomplete

---------

Co-authored-by: Henrique Sato <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants